<template>
  <div class="schoolDetails">
    <div class="schoolDetails-content">
      <div class="schoolDetails-content-title">{{name}}</div>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px" label-position="top">
        <div class="info-title">
          <img src="../../../../assets/images/basicInfo.png" alt="">
          <div class="info-title-right">基本信息</div>
        </div>
        <el-row style="display: flex;justify-content: space-between">
          <el-col :span="8">
            <el-form-item label="学校名称" prop="name" style="width: 90%">
              <el-input v-model="form.name" placeholder="请输入学校名称" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="状态" prop="status">
              <el-select v-model="form.status" placeholder="请选择状态" style="width: 90%">
                <el-option
                  v-for="dict in dict.type.classai_common_status"
                  :key="dict.value"
                  :label="dict.label"

                  :value="parseInt(dict.value)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="学校类型" prop="schoolType">
              <el-select v-model="form.schoolType" placeholder="请选择学校类型" style="width: 90%">
                <el-option
                  v-for="dict in dict.type.school_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="parseInt(dict.value)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row style="display: flex;justify-content: flex-start">
          <el-col :span="8">
            <el-form-item label="建校时间" prop="establishedDate">
              <el-date-picker clearable
                              v-model="form.establishedDate"
                              type="date"
                              value-format="yyyy-MM-dd"
                              style="width: 90%"
                              placeholder="请选择建校时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row style="display: flex;justify-content: flex-start">
          <el-col :span="8">
            <el-form-item label="学校背景" prop="logoPath">
              <image-upload v-model="form.logoPath" :limit="1"/>
            </el-form-item>
          </el-col>
        </el-row>
        <div class="info-title">
          <img src="../../../../assets/images/contactInfo.png" alt="">
          <div class="info-title-right">联系信息</div>
        </div>
        <el-row style="display: flex;justify-content: space-between">
          <el-col :span="8">
            <el-form-item label="联系人" prop="contact" style="width: 90%">
              <el-input v-model="form.contact" placeholder="请输入联系人" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="联系电话" prop="contactMobile" style="width: 90%">
              <el-input v-model="form.contactMobile" placeholder="请输入联系电话" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="电子邮箱" prop="email"  style="width: 90%">
              <el-input v-model="form.email" placeholder="请输入邮箱" />
            </el-form-item>
          </el-col>
        </el-row>
        <div class="info-title">
          <img src="../../../../assets/images/addressInfo.png" alt="">
          <div class="info-title-right">地址信息</div>
        </div>
        <el-row style="display: flex;justify-content: space-between">
          <el-col :span="8" style="display: flex">
            <el-form-item label="所在区域" prop="city" style="width: 44%;margin-right: 2%">
              <el-input v-model="form.city" placeholder="请输入省市" />
            </el-form-item>
            <el-form-item label=" -"  style="width: 44%">
              <el-input v-model="form.area" placeholder="请输入市区" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="详细地址" prop="address" style="width: 90%">
              <el-input v-model="form.address" placeholder="请输入学校地址" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="邮政编码" prop="postalCode" style="width: 90%">
              <el-input v-model="form.postalCode" placeholder="请输入邮政编码" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row style="display: flex;justify-content: flex-start">
          <el-col :span="24">
            <el-form-item label="学校简介" prop="description" style="width: 97%">
              <el-input v-model="form.description" :rows="5" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
        </el-row>
        <div class="info-title">
          <img src="../../../../assets/images/attachment.png" alt="">
          <div class="info-title-right">附件材料</div>
        </div>
        <el-form-item label="附件" prop="attachment">
          <file-upload v-model="form.attachment" :fileSize ='10' :fileType="['pdf','jpg','png']" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer" style="display: flex;justify-content: center">
        <el-button type="primary" @click="submitForm">确 定</el-button>
<!--        <el-button @click="cancel">取 消</el-button>-->
      </div>
    </div>
  </div>
</template>

<script>
import { listSchool, getSchool, delSchool, addSchool, updateSchool } from "@/api/classai/school";
import pieEcharts from "@/views/components/pieEcharts1/index.vue";
import barEcharts from "@/views/components/barEcharts/index.vue";

export default {
  name: "schoolDetails",
  dicts: ['classai_common_status', 'school_type'],
  components:{pieEcharts,barEcharts},
  data() {
    return {
      name:'',
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 学校信息表格数据
      schoolList: [],
      // 弹出层标题
      title: "",
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        city: null,
        area: null,
        address: null,
        postalCode: null,
        schoolType: null,
        establishedDate: null,
        description: null,
        logoPath: null,
        status: null,
        contact: null,
        contactMobile: null,
        email: null,
        attachment: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        name: [
          { required: true, message: "学校名称不能为空", trigger: "blur" }
        ],
        status: [
          { required: true, message: "状态不能为空", trigger: "change" }
        ],
        schoolType: [
          { required: true, message: "学校类型不能为空", trigger: "change" }
        ],
        establishedDate: [
          { required: true, message: "建校时间不能为空", trigger: "change" }
        ],
        contact: [
          { required: true, message: "联系人不能为空", trigger: "blur" }
        ],
        contactMobile: [
          { required: true, message: "联系电话不能为空", trigger: "blur" }
        ],
        email: [
          { required: true, message: "电子邮箱不能为空", trigger: "blur" }
        ],
        city: [
          { required: true, message: "所在区域不能为空", trigger: "blur" }
        ],
        area: [
          { required: true, message: "所在市区不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.name = this.$route.query.name
    if(this.$route.query.id) return  this.getList();
    this.reset()
  },
  methods: {
    /** 查询学校信息列表 */
    getList() {
      this.loading = true;
      getSchool(this.$route.query.id).then(response => {
        this.form = response.data
        // this.schoolList = response.rows;
        // this.total = response.total;
        // this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        city: null,
        area: null,
        address: null,
        postalCode: null,
        schoolType: null,
        establishedDate: null,
        description: null,
        logoPath: null,
        createTime: null,
        updateTime: null,
        status: null,
        contact: null,
        contactMobile: null,
        email: null,
        attachment: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.name = ''
      this.queryParams.status = ''
      this.queryParams.schoolType = ''
      this.queryParams.contact = ''
      this.queryParams.contactMobile = ''
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.title = "添加学校信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getSchool(id).then(response => {
        this.form = response.data;
        this.title = "修改学校信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateSchool(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.getList();
              this.$router.back()
            });
          } else {
            addSchool(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.$router.back()
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      let arr = [row.id || this.ids]
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除学校信息编号为"' + ids + '"的数据项？').then(function() {
        return delSchool(arr);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('classai/school/export', {
        ...this.queryParams
      }, `school_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style lang="scss" scoped>
.schoolDetails{
  width: 100%;
  height: 100%;
  padding: 24px;
  box-sizing: border-box;
  background: #F9FAFB;
  .schoolDetails-content-title{
    font-size: 24px;
    font-weight: bold;
    line-height: 32px;
    color: #1F2937;
    margin-bottom: 32px;
  }
  .schoolDetails-content{
    width: 100%;
    height: 100%;
    padding: 32px;
    box-sizing: border-box;
    background: linear-gradient(0deg, rgba(0, 0, 0, 0.001), rgba(0, 0, 0, 0.001)), #FFFFFF;
    box-shadow: 0px 2px 4px -2px rgba(0, 0, 0, 0.1),0px 4px 6px -1px rgba(0, 0, 0, 0.1);
    overflow-y: auto;
  }

}
.normal-button{
  font-size: 12px;
  background: #DCFCE7;
  color: #166534;
}
.stop-button{
  font-size: 12px;
  background: #FEF9C3;
  color: #854D0E;
}
.info-title{
  width: 100%;
  display: flex;
  align-items: center;
  padding-bottom: 8px;
  box-sizing: border-box;
  border-bottom: 1px solid #E5E7EB;
  margin-bottom: 16px;
  img{
    height: 18px;
    margin-right: 10px;
  }
  .info-title-right{
    font-size: 18px;
    font-weight: 600;
    line-height: 28px;
    color: #374151;
  }
}
</style>
